//
//  YYRDatePickerView.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/10.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "YYRDatePickerView.h"

#define screenWith  [UIScreen mainScreen].bounds.size.width
#define screenHeight [UIScreen mainScreen].bounds.size.height
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// 获取RGB颜色
//#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:a]

@interface YYRDatePickerView ()<UIPickerViewDataSource,UIPickerViewDelegate> {
    NSInteger yearRange;
    NSInteger dayRange;
    NSInteger startYear;
    NSInteger selectedYear;
    NSInteger selectedMonth;
    NSInteger selectedDay;
    NSInteger selectedHour;
    NSInteger selectedMinute;
    NSInteger selectedSecond;
    
    //左边退出按钮
    UIButton *cancelButton;
    //右边的确定按钮
    UIButton *chooseButton;
}

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, copy) NSString *string;
@property (nonatomic, strong) UITextField *field;

@property (nonatomic,strong) UIWindow *alertWindow;

@property (nonatomic,strong) UIView *alertView;

@property (nonatomic,strong) UIView *backgroundView;

@property (nonatomic,strong) UITapGestureRecognizer *tap;

@end
@implementation YYRDatePickerView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self internalConfig];
    }
    return self;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)showDateTimePickerView {
    [self setCurrentDate:[NSDate date]];
    _backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
    [IQKeyboardManager sharedManager].enable = NO;
    [_field becomeFirstResponder];
}

- (void)hideDateTimePickerView {
    [self removeFromSuperview];
    [self endEditing:YES];
    [IQKeyboardManager sharedManager].enable = YES;
}

- (void)cancelButtonClick {
    [self hideDateTimePickerView];
}

- (void)configButtonClick {
    if (self.confirmCompletionBlock) {
        self.confirmCompletionBlock(self.string);
    }
    [self hideDateTimePickerView];
}

- (void)tap:(UITapGestureRecognizer *)tap{
    [self hideDateTimePickerView];
}

- (void)internalConfig {
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];

    self.frame =[UIScreen mainScreen].bounds;
    
    //添加 底部遮罩
    _backgroundView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    [self addSubview:_backgroundView];
    [self setUserInteractionEnabled:YES];
    [self setMultipleTouchEnabled:NO];
    [self.backgroundView setUserInteractionEnabled:YES];
    [self.backgroundView setMultipleTouchEnabled:NO];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    self.tap = tap;
    [_backgroundView addGestureRecognizer:tap];
    
    _field = [[UITextField alloc] init];
    _field.hidden = YES;
    [self addSubview:_field];
    
    self.pickerView = [[UIPickerView alloc] init];
    self.pickerView.backgroundColor = [UIColor whiteColor];
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
    
    //盛放按钮的View
    UIView *upVeiw = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
    upVeiw.backgroundColor = [UIColor whiteColor];
    
    //左边的取消按钮
    cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(12, 0, 40, 40);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    cancelButton.backgroundColor = [UIColor clearColor];
    cancelButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [cancelButton setTitleColor:UIColorFromRGB(0x0d8bf5) forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [upVeiw addSubview:cancelButton];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.center = upVeiw.center;
    titleLabel.text = self.title;
    titleLabel.center = upVeiw.center;
    titleLabel.bounds = CGRectMake(0, 0, screenWith/2, 32);
    [upVeiw addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    //右边的确定按钮
    chooseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    chooseButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 52, 0, 40, 40);
    [chooseButton setTitle:@"确定" forState:UIControlStateNormal];
    chooseButton.backgroundColor = [UIColor clearColor];
    chooseButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [chooseButton setTitleColor:UIColorFromRGB(0x0d8bf5) forState:UIControlStateNormal];
    [chooseButton addTarget:self action:@selector(configButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [upVeiw addSubview:chooseButton];
    
    //分割线
    UIView *splitView = [[UIView alloc] initWithFrame:CGRectMake(0, 39, [UIScreen mainScreen].bounds.size.width, 0.5)];
    splitView.backgroundColor = UIColorFromRGB(0xe6e6e6);
    [upVeiw addSubview:splitView];
    
    _field.inputView = self.pickerView;
    _field.inputAccessoryView = upVeiw;
    
    NSCalendar *calendar0 = [NSCalendar currentCalendar];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *comps  = [calendar0 components:unitFlags fromDate:[NSDate date]];
    NSInteger year = [comps year];
    
    startYear = year - 100;
    yearRange = 200;
    
    [self setCurrentDate:[NSDate date]];
}


// 默认时间的处理
- (void)setCurrentDate:(NSDate *)currentDate {
    
    // 获取当前时间
    NSCalendar *calendar0 = [NSCalendar currentCalendar];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *comps  = [calendar0 components:unitFlags fromDate:currentDate];
    
    NSInteger year = [comps year];
    NSInteger month = [comps month];
    NSInteger day = [comps day];
    NSInteger hour = [comps hour];
    NSInteger minute = [comps minute];
    NSInteger second = [comps second];
    
    selectedYear = year;
    selectedMonth = month;
    selectedDay = day;
    selectedHour = hour;
    selectedMinute = minute;
    selectedSecond = second;
    
    dayRange = [self isAllDay:year andMonth:month];
    
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        [self.pickerView selectRow:month-1 inComponent:1 animated:NO];
        [self.pickerView selectRow:day-1 inComponent:2 animated:NO];
        [self.pickerView selectRow:hour inComponent:3 animated:NO];
        [self.pickerView selectRow:minute inComponent:4 animated:NO];
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        [self pickerView:self.pickerView didSelectRow:month-1 inComponent:1];
        [self pickerView:self.pickerView didSelectRow:day-1 inComponent:2];
        [self pickerView:self.pickerView didSelectRow:hour inComponent:3];
        [self pickerView:self.pickerView didSelectRow:minute inComponent:4];
        
        
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        [self.pickerView selectRow:month-1 inComponent:1 animated:NO];
        [self.pickerView selectRow:day-1 inComponent:2 animated:NO];
        [self.pickerView selectRow:hour inComponent:3 animated:NO];
        [self.pickerView selectRow:minute inComponent:4 animated:NO];
        [self.pickerView selectRow:second inComponent:5 animated:NO];
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        [self pickerView:self.pickerView didSelectRow:month-1 inComponent:1];
        [self pickerView:self.pickerView didSelectRow:day-1 inComponent:2];
        [self pickerView:self.pickerView didSelectRow:hour inComponent:3];
        [self pickerView:self.pickerView didSelectRow:minute inComponent:4];
        [self pickerView:self.pickerView didSelectRow:second inComponent:5];
        
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        [self.pickerView selectRow:month-1 inComponent:1 animated:NO];
        [self.pickerView selectRow:day-1 inComponent:2 animated:NO];
        [self.pickerView selectRow:hour inComponent:3 animated:NO];
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        [self pickerView:self.pickerView didSelectRow:month-1 inComponent:1];
        [self pickerView:self.pickerView didSelectRow:day-1 inComponent:2];
        [self pickerView:self.pickerView didSelectRow:hour inComponent:3];
        
        
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        [self.pickerView selectRow:month-1 inComponent:1 animated:NO];
        [self.pickerView selectRow:day-1 inComponent:2 animated:NO];
        
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        [self pickerView:self.pickerView didSelectRow:month-1 inComponent:1];
        [self pickerView:self.pickerView didSelectRow:day-1 inComponent:2];
        
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        [self.pickerView selectRow:month-1 inComponent:1 animated:NO];
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        [self pickerView:self.pickerView didSelectRow:month-1 inComponent:1];
        
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode) {
        [self.pickerView selectRow:year-startYear inComponent:0 animated:NO];
        
        [self pickerView:self.pickerView didSelectRow:year-startYear inComponent:0];
        
        
    }
    [self.pickerView reloadAllComponents];
}

#pragma mark - 选择对应月份的天数
- (NSInteger)isAllDay:(NSInteger)year andMonth:(NSInteger)month {
    int day = 0;
    switch(month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            day=31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            day = 30;
            break;
        case 2: {
            if(((year % 4 == 0) && (year % 100 != 0))||(year % 400 == 0)) {
                day = 29;
                break;
            } else {
                day = 28;
                break;
            }
        }
        default:
            break;
    }
    return day;
}

#pragma mark -- UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        return 5;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode){
        return 6;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode){
        return 4;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode){
        return 3;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode){
        return 2;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode){
        return 1;
    }
    return 0;
}

// 确定每一列返回的东西
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        switch (component) {
            case 0: {
                return yearRange;
            }
                break;
            case 1: {
                return 12;
            }
                break;
            case 2: {
                return dayRange;
            }
                break;
            case 3: {
                return 24;
            }
                break;
            case 4: {
                return 60;
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode){
        switch (component) {
            case 0: {
                return yearRange;
            }
                break;
            case 1: {
                return 12;
            }
                break;
            case 2: {
                return dayRange;
            }
                break;
            case 3: {
                return 24;
            }
                break;
            case 4: {
                return 60;
            }
                break;
                
            case 5: {
                return 60;
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode){
        switch (component) {
            case 0: {
                return yearRange;
            }
                break;
            case 1: {
                return 12;
            }
                break;
            case 2: {
                return dayRange;
            }
                break;
            case 3: {
                return 24;
            }
                break;
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode){
        switch (component) {
            case 0:  {
                return yearRange;
            }
                break;
            case 1: {
                return 12;
            }
                break;
            case 2: {
                return dayRange;
            }
                break;
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode) {
        switch (component) {
            case 0: {
                return yearRange;
            }
                break;
            case 1: {
                return 12;
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode) {
        switch (component) {
            case 0: {
                return yearRange;
            }
                break;
                
            default:
                break;
        }
    }
    return 0;
}

#pragma mark -- UIPickerViewDelegate

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont boldSystemFontOfSize:16.0];
    label.textAlignment = NSTextAlignmentCenter;
    
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            case 2: {
                label.text = [NSString stringWithFormat:@"%ld日",(long)row+1];
            }
                break;
            case 3:  {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld时",(long)row];
            }
                break;
            case 4: {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld分",(long)row];
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode) {
        
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            case 2: {
                label.text = [NSString stringWithFormat:@"%ld日",(long)row+1];
            }
                break;
            case 3: {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld时",(long)row];
            }
                break;
            case 4: {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld分",(long)row];
            }
                break;
            case 5: {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld秒",(long)row];
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode) {
        
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            case 2: {
                
                label.text = [NSString stringWithFormat:@"%ld日",(long)row+1];
            }
                break;
            case 3: {
                label.textAlignment = NSTextAlignmentRight;
                label.text = [NSString stringWithFormat:@"%ld时",(long)row];
            }
                break;
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode){
        
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            case 2: {
                
                label.text = [NSString stringWithFormat:@"%ld日",(long)row+1];
            }
                break;
                
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode) {
        
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            default:
                break;
        }
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode) {
        
        switch (component) {
            case 0: {
                label.text = [NSString stringWithFormat:@"%ld年",(long)(startYear + row)];
            }
                break;
            case 1: {
                label.text = [NSString stringWithFormat:@"%ld月",(long)row+1];
            }
                break;
            default:
                break;
        }
    }
    return label;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    CGFloat autoSizeScale = 1.0;
    if (screenWith > 320) { // 适配
        autoSizeScale = screenWith / 320;
    }
    CGFloat spaceWidth = 80 * autoSizeScale;
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        if (component == 0) { // 适配
            return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/5 + 30;
        }
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/5;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode) {
        if (component == 0) { // 适配
            return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/6 + 30;
        }
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/6;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode) {
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/4;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode) {
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/3;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode) {
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/2;
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode) {
        return ([UIScreen mainScreen].bounds.size.width-spaceWidth)/1;
    }
    
    return 0;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    
    return 30;
}
// 监听picker的滑动
- (void)pickerView:(UIPickerView *)pickerView
      didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteMode) {
        switch (component) {
            case 0: {
                selectedYear = startYear + row;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 1: {
                selectedMonth = row+1;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 2: {
                selectedDay = row+1;
            }
                break;
            case 3: {
                selectedHour = row;
            }
                break;
            case 4: {
                selectedMinute = row;
            }
                break;
                
            default:
                break;
        }
        
        _string = [NSString stringWithFormat:@"%ld-%.2ld-%.2ld %.2ld:%.2ld",selectedYear,selectedMonth,selectedDay,selectedHour,selectedMinute];
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMinuteSecondMode) {
        switch (component) {
            case 0: {
                selectedYear = startYear + row;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 1: {
                selectedMonth = row + 1;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 2: {
                selectedDay = row + 1;
            }
                break;
            case 3: {
                selectedHour = row;
            }
                break;
            case 4: {
                selectedMinute = row;
            }
                break;
            case 5: {
                selectedSecond = row;
            }
                break;
            default:
                break;
        }
        
        _string =[NSString stringWithFormat:@"%ld-%.2ld-%.2ld %.2ld:%.2ld:%.2ld",selectedYear,selectedMonth,selectedDay,selectedHour,selectedMinute,selectedSecond];
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayHourMode) {
        switch (component) {
            case 0:  {
                selectedYear = startYear + row;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 1: {
                selectedMonth = row + 1;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 2: {
                selectedDay = row + 1;
            }
                break;
            case 3:  {
                selectedHour = row;
            }
                break;
                
            default:
                break;
        }
        
        _string = [NSString stringWithFormat:@"%ld-%.2ld-%.2ld %.2ld",selectedYear,selectedMonth,selectedDay,selectedHour];
    }  else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthDayMode) {
        switch (component) {
            case 0: {
                selectedYear = startYear + row;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 1: {
                selectedMonth = row+1;
                dayRange = [self isAllDay:selectedYear andMonth:selectedMonth];
                [self.pickerView reloadComponent:2];
            }
                break;
            case 2: {
                selectedDay = row+1;
            }
                break;
                
            default:
                break;
        }
        
        _string =[NSString stringWithFormat:@"%ld-%.2ld-%.2ld",selectedYear,selectedMonth,selectedDay];
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMonthMode) {
        switch (component) {
            case 0: {
                selectedYear = startYear + row;
                
            }
                break;
            case 1: {
                selectedMonth = row+1;
                
            }
                break;
                
            default:
                break;
        }
        
        _string =[NSString stringWithFormat:@"%ld-%.2ld",selectedYear,selectedMonth];
    } else if (self.pickerViewMode == YYRDatePickerViewDateYearMode) {
        switch (component) {
            case 0: {
                selectedYear = startYear + row;
                
            }
                break;
                
            default:
                break;
        }
        
        _string = [NSString stringWithFormat:@"%ld",selectedYear];
    }
}


@end
